//Compile: make
//Run: ./annlite_test /home/gary/Code/vector-ssd/annlite_builder/sift_base_1000

#include <iostream>
#include "annlite.h"

using namespace std;
using json = nlohmann::json;
// #define FTYPE float
// #define FTYPE uint8_t //数据集的数据类型。目前的版本在makefile中定义

int main(int argc, char** argv){  
    
    //user_config的路径
    string user_config_path = "./user_config.json";
    if(argc == 2){
        user_config_path = argv[1];
    }
    else{
        cout << "User have not set config file path, use " << user_config_path << " by default" << endl;
    }

    //加载配置文件
    json dataset_config;
    json user_config;
    load_config(user_config_path, user_config);
    printJson(user_config);
    //从用户配置中读取数据集配置
    string dataset_config_path = user_config["index_root_path"];
    dataset_config_path += "/dataset_config.json";
    load_config(dataset_config_path, dataset_config);
    printJson(dataset_config);

    //加载索引
    ANNLite<FTYPE> annlite(user_config, dataset_config);

    //加载测试集
    QuerySet<FTYPE> query_set(user_config, dataset_config);

    //进行检索，检索的结果存入query_set
    annlite.search(query_set);

    //计算召回率，这里分成2步骤是便于统计时间,避免统计时间和计算召回率的时间被统计进检索时间
    query_set.output_results();

    return 0;
}